package pers.jason.wppm.security.core.social.oicq.connect;

import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
import pers.jason.wppm.security.core.social.oicq.api.OicqApiBinding;
import pers.jason.wppm.security.core.social.oicq.api.OicqApiBindingImpl;

/**
 * providerservice组件：整个oauth2协议认证的核心组件
 */
public class OicqServiceProvider extends AbstractOAuth2ServiceProvider<OicqApiBinding> {

    private String appId;

    /**
     * 将用户导向服务提供商进行授权申请
     */
    private static final String URL_AUTHORICE_GET = "https://graph.qq.com/oauth2.0/authorize";

    /**
     * 使用授权码请求token
     */
    private static final String URL_REQUEST_TOKEN_GET = "https://graph.qq.com/oauth2.0/token";


    public OicqServiceProvider(String appId, String appSecret) {
        super(new OicpOAuth2Template(appId, appSecret, URL_AUTHORICE_GET, URL_REQUEST_TOKEN_GET));
        this.appId = appId;
    }

    @Override
    public OicqApiBinding getApi(String accessToken) {
        return new OicqApiBindingImpl(accessToken, appId);
    }
}
